package com.ruoyi.qywx.getway.request;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import lombok.Builder;
import lombok.Getter;

/**
 * @author : hcl
 * @Date : 2023/8/7
 */
@Getter
public class TxResponse {
    private final boolean success;
    private JSONObject json;

    public TxResponse() {
        this.success = false;
    }

    public static TxResponse error(String err) {
        TxResponse response = new TxResponse();
        JSONObject json = new JSONObject();
        json.set("errmsg", err);
        response.json = json;
        return response;
    }

    public TxResponse(boolean success, JSONObject json) {
        this.success = success;
        this.json = json;
    }

    public String getError() {
        ErrorCode errcode = ErrorCode.of(json.getInt("errcode"));
        if (errcode != null) return errcode.getErr();
        return json.toString();
    }

}
